package com.sy.simpleegg.room.repository

import com.sy.simpleegg.room.dao.OutDao
import com.sy.simpleegg.room.entity.OutEntity
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class OutRepository(private val outDao: OutDao) {

    suspend fun getAll(): List<OutEntity>?{
        return withContext(Dispatchers.IO){
            outDao.getAll()
        }
    }

    suspend fun getByUuid(uuid: String): List<OutEntity>?{
        return withContext(Dispatchers.IO){
            outDao.getByUuidd(uuid)
        }
    }

    suspend fun updateById(id: Long, state: Int){
        withContext(Dispatchers.IO){
            outDao.updateStateById(id, state)
        }
    }

    suspend fun updateByUuid(uuid: String, state: Int){
        withContext(Dispatchers.IO){
            outDao.updateStateByUuid(uuid, state)
        }
    }

    suspend fun insert(outEntity: OutEntity){
        withContext(Dispatchers.IO){
            outDao.insert(outEntity)
        }
    }

    suspend fun insertAll(outEntities: List<OutEntity>){
        withContext(Dispatchers.IO){
            outDao.insertAll(outEntities)
        }
    }

    suspend fun delete(outEntity: OutEntity){
        withContext(Dispatchers.IO){
            outDao.delete(outEntity)
        }
    }

    suspend fun deleteAll(){
        withContext(Dispatchers.IO){
            outDao.deleteAll()
        }
    }

    suspend fun deleteByUuid(uuid: String){
        withContext(Dispatchers.IO){
            outDao.deleteByUuid(uuid)
        }
    }

    suspend fun deleteById(id: Long){
        withContext(Dispatchers.IO){
            outDao.deleteById(id)
        }
    }
}